﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using YouxinHelper.Helper.Currency;

namespace YouxinHelper.Youxin.Local
{
    internal class GetLocalList
    {
        static string ListPath = ".\\List\\";
        internal static void Start(TextBox textBox4, RichTextBox richTextBox1)
        {
            FloderHelper.FloderExits(ListPath, true);
            List<string> TempFileList = FileHelper.GetFullFileNameList(ListPath);
            if (TempFileList.Count == 0)
            { Console.WriteLine("资源不足"); return; }
            int Randomcount = new Random().Next(TempFileList.Count);
            String FilePath = TempFileList[Randomcount];
            TempFileList.RemoveAt(Randomcount);
            Console.WriteLine("读取文件路径{0}",FilePath);
            textBox4.Text = Path.GetFileNameWithoutExtension(FilePath);
            richTextBox1.Text = CreateContent(FileHelper.ReadAllLine(FilePath));
            FileHelper.FileDelete(FilePath);
        }

        private static string CreateContent(List<string> list)
        {
            string Content = "已注明CN，若有任何问题请私信告诉我，侵删致歉，喜欢请给给糖糖给福利姬哦！\r\n";
            foreach (string line in list) {
                if (line == "")
                    continue;
                Content += string.Format("![]({0})",TextHelper.ReplaceText(line,"\\(.*?\\)",""));
            }
            return Content;
        }
    }
}